﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Semantics;
namespace GraphBase.Presentation.SubGraph
{
    public partial class SubGraphForm : Form
    {
        private IGraph ParentGraph;
        public SubGraphForm(IGraph graph,IGraph subgraph)
        {
            InitializeComponent();
            this.ParentGraph = graph;
            this.graphGraphUserControl1.Graph = subgraph;
        }

        private void SubGraphForm_Load(object sender, EventArgs e)
        {
            if(this.graphGraphUserControl1.Graph is Node)
                this.Text += " - " + ((Node)this.graphGraphUserControl1.Graph).Label;
            this.graphGraphUserControl1.RefreshGraph();
        }

        private void graphGraphUserControl1_NodeOpenEvent(UI.GraphControlBase sender, Node node)
        {

            if (node is IGraph)
            {
                SubGraph.SubGraphForm subfor = new SubGraph.SubGraphForm(this.graphGraphUserControl1 .Graph ,(IGraph)node);
                subfor.Show(this);
                
            }
        }

        private void graphGraphUserControl1_SelectedNodeChangedEvent(GraphGraphUserControl sender, NodePos selectednode)
        {
            this.SelectedNodeStatusLabel_SetText("选中节点为：" + selectednode.pNode);
        }
        //状态栏显示选中节点
        public ToolStripStatusLabel SelectedNodeStatusLabel_SetText(string text)
        {
            this.SelectedNodeStatusLabel.Text = text;
            return SelectedNodeStatusLabel;
        }

        private void RefreshButton_Click(object sender, EventArgs e)
        {
            try
            {
                this.graphGraphUserControl1.RefreshGraph();
            }
            catch (Exception exp)
            {
                MessageBox.Show(this, exp.ToString());
            }
        }

        private void graphGraphUserControl1_SelectedEdgeChangedEvent(GraphGraphUserControl sender, EdgePos selectedline)
        {
            if (selectedline == null)
                this.selectedEdgeToolStripStatusLabel_SetText("无选中边");
            else
                this.selectedEdgeToolStripStatusLabel_SetText("选中边为：" + selectedline.pedge.ToString());
        }
        //状态栏显示选中的边
        public ToolStripStatusLabel selectedEdgeToolStripStatusLabel_SetText(string text)
        {
            this.selectedEdgeToolStripStatusLabel.Text = text;
            return selectedEdgeToolStripStatusLabel;
        }
        /// <summary>
        /// 可视化增加节点到子图
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void enrollNodeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddNodeDialog addnodeDialog = new AddNodeDialog(this.ParentGraph, this.graphGraphUserControl1.Graph);

            if (addnodeDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                this.graphGraphUserControl1.RefreshGraph();


        }
    }
}
